package dk.soegaard.simpleuddibrowser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;

import dk.soegaard.simpleuddibrowser.style.Styles;
import dk.soegaard.simpleuddibrowser.transport.Inquery;

public class GetDetailHandler {
	private Styles styles; 
	
	public GetDetailHandler() {
		styles = new Styles();
	}
	
	
	public void getBusinessDetail(String uddiId, OutputStream resultStream) throws TransformerException {
		String getBusinessDetail = "<get_businessDetail xmlns:uddi=\"urn:uddi-org:api_v3\"><uddi:businessKey>"+uddiId+"</uddi:businessKey></get_businessDetail>";
		invoke(getBusinessDetail, resultStream, styles.getBusinessDetailStyle());
	}
	
	public void getServiceDetail(String uddiId, OutputStream resultStream) throws TransformerException {
		String getBusinessDetail = "<get_serviceDetail xmlns:uddi=\"urn:uddi-org:api_v3\"><uddi:serviceKey>"+uddiId+"</uddi:serviceKey></get_serviceDetail>";
		invoke(getBusinessDetail, resultStream, styles.getServiceDetailStyle());
	}
	
	public void getBindingDetail(String uddiId, OutputStream resultStream) throws TransformerException {
		String getBusinessDetail = "<get_bindingDetail xmlns:uddi=\"urn:uddi-org:api_v3\"><uddi:bindingKey>"+uddiId+"</uddi:bindingKey></get_bindingDetail>";
		invoke(getBusinessDetail, resultStream, styles.getBindingDetailStyle());
	}
	
	public void getTModelDetail(String uddiId, OutputStream resultStream) throws TransformerException {
		String getBusinessDetail = "<get_tModelDetail xmlns:uddi=\"urn:uddi-org:api_v3\"><uddi:tModelKey>"+uddiId+"</uddi:tModelKey></get_tModelDetail>";
		invoke(getBusinessDetail, resultStream, styles.getTModelDetailStyle());
	}
	
	private void invoke(String xmlRequest, OutputStream resultStream, Transformer style) throws TransformerException {
		Inquery inquery = new  Inquery();
		byte[] bytes = xmlRequest.getBytes();
		InputStream inputStream = new ByteArrayInputStream(bytes);
    	inquery.invoke(inputStream, resultStream, style);
	}
}
